MWF.xApplication.Common = MWF.xApplication.Common || {
	options: {
		"multitask": false,	//允许多窗口运行
		"executable": true	//可执行
	}
};
MWF.require("MWF.xDesktop.Window", null, false);

(function () {
	var removeOn = function (string) {
		return string.replace(/^on([A-Z])/, function (full, first) {
			return first.toLowerCase();
		});
	};
	Events.implement({
		"fireEvent": function (type, args, delay) {
			if (this.options && this.options.name && MWF.xDesktop && MWF.xDesktop.$globalEvents) {
				if (MWF.xDesktop.$globalEvents[this.options.name]) {
					var evs = MWF.xDesktop.$globalEvents[this.options.name][type];
					if (evs) {
						evs.each(function (fn) {
							if (delay) fn.delay(delay, this, args);
							else fn.apply(this, args);
						}, this);
					}
				}
			}

			type = removeOn(type);
			var events = this.$events[type];
			if (!events) return this;
			args = Array.convert(args);
			events.each(function (fn) {
				if (delay) fn.delay(delay, this, args);
				else fn.apply(this, args);
			}, this);
			return this;
		}
	});
})();

MWF.xApplication.Common.Main = new Class({
	Extends: MWF.widget.Common,
	Implements: [Options, Events],

	options: {
		"desktopReload": true,
		"style": "default",
		"name": "Common",
		"icon": "", //图标
		"title": "", //标题
		"event": null,
		"width": "800",
		"height": "600",
		"isResize": true,
		"isMax": true,
		"setCurrent": true,
		"isRefresh": false,
		"isWindowRefresh": true,
		"embededParent": ""
	},
	initialize: function (desktop, options) {
		this.setOptions(options);
		this.desktop = desktop;

		this.path = "../x_component_" + this.options.name.replace(/\./g, "_") + "/$Main/";
		this.options.icon = this.path + this.options.style + "/" + this.options.icon;

		this.cssPath = this.path + this.options.style + "/css.wcss";
		if (this.options.mvcStyle) this.stylePath = this.path + this.options.style + "/" + this.options.mvcStyle;
		if (!this.options.mvcStyle) this._loadCss();

		if( this.options.embededParent && o2.typeOf(this.options.embededParent)==="element" ){
			this.embeded = true;
		}
	},
	fireAppEvent: function (when) {
		this.fireEvent(when);
		if (this[("on-" + when).camelCase()]) this[("on-" + when).camelCase()]();
		//		if (this[("on-"+when).camelCase()+"Events"){
		//			this[("on-"+when).camelCase()+"Events".each(function(event){
		//				event.apply(this);
		//			}.bind(this));
		//		}
	},
	loadNoAnimation: function (isCurrent, max, hide) {
		this.fireAppEvent("queryLoad");
		if( this.embeded ){
			this.loadEmbeded();
		}else if (!this.inBrowser) {
			if (layout.viewMode==="Homepage"){
				this.loadWindowFlat(isCurrent);
			}else{
				this.loadWindow(isCurrent, false, max, hide);
			}
		} else {
			this.loadInBrowser(isCurrent);
		}
	},
	load: function (isCurrent, content) {
		this.fireAppEvent("queryLoad");
		if( this.embeded ){
			this.loadEmbeded();
		}else if (!this.inBrowser) {
			if (layout.viewMode==="Default"){
				this.loadWindowFlat(isCurrent);
			}else{
				this.loadWindow(isCurrent);
			}
		} else {
			this.loadInBrowser(content);
		}
	},
	loadApplication: function (callback) {
		if (callback) callback();
	},
	loadWindow: function (isCurrent, animation, max, hide) {
		this.fireAppEvent("queryLoadWindow");
		var options = {
			"style": "desktop_" + this.desktop.options.style,
			"title": this.options.title,
			"isResize": this.options.isResize,
			"isMax": this.options.isMax,
			"isRefresh": this.options.isWindowRefresh,
			"container": this.desktop.node,
			"onPostShow": function () {
				if (isCurrent) this.setCurrent();
				this.fireAppEvent("postLoadWindow");
				this.fireAppEvent("queryLoadApplication");
				//load css
				if (this.options.title) this.setTitle(this.options.title);
				if (this.stylePath) {
					(this.window.node || this.content).loadCss(this.stylePath, this.loadWindowApplication.bind(this));
				}else{
					this.loadWindowApplication();
				}
			}.bind(this),
			"onResize": function () {
				this.window.options.title = this.options.title;
				this.window.getTitle();
				this.fireAppEvent("resize");
			}.bind(this),
			"onResizeCompleted": function () {
				this.fireAppEvent("resizeCompleted");
			}.bind(this),
			"onMoveDrop": function (e) {
				if (Browser.name == "firefox") {
					if (e.event.clientX < 0 || e.event.clientY < 0) this.openInNewBrowser();
				} else {
					if (e.event.x < 0 || e.event.y < 0) this.openInNewBrowser();
				}

			}.bind(this)
		};

		if (this.options.event) {
			options.fromTop = this.options.event.page.y;
			options.fromLeft = this.options.event.page.x;
		}
		options.width = this.options.width || options.width;
		options.height = this.options.height || options.height;

		this.window = new MWF.xDesktop.Window(this, options);
		this.fireAppEvent("loadWindow");
		//this.maxSize();
		this.content = this.window.content;
		if (animation === false) {
			this.window.showNoAnimation(max, hide);
		} else {
			this.window.show();
		}
	},
	loadWindowApplication: function(){
		this.setContentEvent();
		this.content.addClass("appContent");
		this.loadApplication(function () {
			this.fireAppEvent("postLoadApplication");
		}.bind(this));
		this.fireAppEvent("postLoad");
	},

	loadWindowFlat: function (isCurrent) {
		this.window = {
			"app": this,
			"isHide": false,
			"isMax": true,
			"maxSize": function () { },
			"restore": function () { },
			"setCurrent": function () {
				//this.content.show();
				this.window.node.removeClass("layout_component_node_hide");
				this.window.node.addClass("layout_component_node_show");
				//this.window.node.fade("in");
			}.bind(this),
			"setUncurrent": function () {
				//this.content.hide();
				this.window.node.addClass("layout_component_node_hide");
				this.window.node.removeClass("layout_component_node_show");
				//this.window.node.fade("out");
			}.bind(this),
			"hide": function () { },
			"maxOrRestoreSize": function () { },
			"restoreSize": function () { },
			"close": function (callback) {
				this.content.destroy();
				if (callback) callback();
			}.bind(this)
		};

        // var component = this;
        // var OaComponent = class  extends HTMLDivElement {
        //     constructor() {
        //         super();
        //         var shadow = this.attachShadow({mode: 'open'});
        //
        //         // var shadow = layout.desktop.contentNode.attachShadow({mode: 'open'});
        //         // component.window.node = shadow;
        //         component.window.content = new Element("div.layout_component_content");
        //         component.content = component.window.content;
        //         shadow.appendChild(component.content);
        //     }
        // };
        // debugger;
        // var id = this.options.name.toLowerCase();
        // //var id = o2.uuid().substring(0,5).toLowerCase();
        // customElements.define('oa-component-'+id, OaComponent);
        // var node = document.createElement("oa-component"+id);
        // node.className="layout_component_node";
        // this.window.node = node;
        // layout.desktop.contentNode.appendChild(node);
        // component.content = new Element("div.layout_component_content").inject(node);

        // this.window.node = new Element("oa-component.layout_component_node").inject(layout.desktop.contentNode);


        // var shadow = layout.desktop.contentNode.attachShadow({mode: 'open'});
        // this.window.node = shadow;
        // this.window.content = new Element("div.layout_component_content");
        // this.content = this.window.content;
        // shadow.appendChild(this.content);

        this.window.node = this.windowNode || new Element("div.layout_component_node").inject(layout.desktop.contentNode);
		this.window.content = new Element("div.layout_component_content").inject(this.window.node);
		this.content = this.window.content;

		//this.window.setUncurrent();

		this.resizeFun = function(){
			this.fireAppEvent("resize");
		}.bind(this);

		layout.desktop.addEvent("resize", this.resizeFun);

		// window.addEventListener("beforeunload", function (e) {
		// 	this.fireAppEvent("queryClose");
		// }.bind(this));
		// window.addEventListener("pagehide", function (e) {
		// 	this.fireAppEvent("queryClose");
		// }.bind(this));

		if (isCurrent){
			this.setCurrent();
		}else{
			this.setUncurrent();
		}
		this.fireAppEvent("postLoadWindow");
		this.fireAppEvent("queryLoadApplication");

		//load css
		if (this.options.title) this.setTitle(this.options.title);
		if (this.stylePath) {
			(this.window.node || this.content).loadCss(this.stylePath, this.loadWindowApplication.bind(this));
		}else{
			this.loadWindowApplication();
		}
	},

	loadInBrowser: function (content) {
		this.window = {
			"isHide": false,
			"isMax": true,
			"maxSize": function () { },
			"restore": function () { },
			"setCurrent": function () {},
			"setUncurrent": function () {},
			"hide": function () { },
			"maxOrRestoreSize": function () { },
			"restoreSize": function () { },
			"close": function () { }
		};
		this.window.titleText = $(document.head).getElement("title");
		try {
			this.window.titleText.set("text", this.options.title);
		} catch (e) { }

		if (content && o2.typeOf(content)==="element") this.window.content = content;
		if (!this.window.content) this.window.content = $("appContent") || $("layout");
		if (!this.window.content) {
			this.window.content = new Element("div", {"styles": {"width": 0, "height": 0}}).inject(document.body);
		}
		this.content = this.window.content;
		//this.content.setStyles({"height": "100%", "overflow": "hidden"});

		window.addEvent("resize", function () {
			this.fireAppEvent("resize");
		}.bind(this));
		// $(document.body).addEvent("resize", function(){
		// 	debugger;
		//     this.fireAppEvent("resize");
		// }.bind(this));
		window.addEventListener("beforeunload", function (e) {
			this.fireAppEvent("queryClose");
		}.bind(this));

		if(layout.mobile){
			window.addEventListener("pagehide", function (e) {
				this.fireAppEvent("queryClose");
			}.bind(this));
		}

		// window.onbeforeunload = function(e){
		//     this.fireAppEvent("queryClose");
		// }.bind(this);

		this.fireAppEvent("postLoadWindow");
		this.fireAppEvent("queryLoadApplication");
		this.setContentEvent();

		if (this.options.title) this.setTitle(this.options.title);
		if (this.stylePath) o2.loadCss(this.stylePath);
		this.content.addClass("appContent");
		this.loadApplication(function () {
			this.fireAppEvent("postLoadApplication");
		}.bind(this));

		//this.content.setStyle("height", document.body.getSize().y);

		this.fireAppEvent("postLoad");
	},

	setEventTarget: function( eventTarget ){
		if( !this.embeded )return;

		if (this.eventTarget){
			if( this.resizeFun )this.eventTarget.removeEvent("resize", this.resizeFun );
			this.resizeFun = null;

			if( this.queryLoadFun )this.eventTarget.removeEvent("resize", this.queryLoadFun );
			this.queryLoadFun = null;

			if( this.postLoadFun )this.eventTarget.removeEvent("resize", this.postLoadFun );
			this.postLoadFun = null;
		}

		if(eventTarget) this.eventTarget = eventTarget;

		if (this.eventTarget){
			this.resizeFun = function () {
				debugger;
				this.fireAppEvent("resize");
			}.bind(this);
			this.eventTarget.addEvent("resize", this.resizeFun);

			this.queryLoadFun = function () {
				this.fireAppEvent && this.fireAppEvent("queryClose");
			}.bind(this);
			this.eventTarget.addEvent("queryClose", this.queryLoadFun);

			this.postLoadFun = function () {
				if (this.resizeFun) this.eventTarget.removeEvent("resize", this.resizeFun);
				this.fireAppEvent && this.fireAppEvent("postClose");
			}.bind(this);
			this.eventTarget.addEvent("postClose", this.postLoadFun);
		}
	},
	loadEmbeded: function(){
		if( !this.options.embededParent )return;

		this.window = {
			"isHide": false,
			"isMax": true,
			"maxSize": function(){},
			"restore": function(){},
			"setCurrent": function(){},
			"setUncurrent": function () {},
			"hide": function(){},
			"maxOrRestoreSize": function(){},
			"restoreSize": function(){},
			"close": function(){},
			"titleText" : {
				set : function(){}
			}
		};
		this.window.content = this.options.embededParent;
		this.content = this.window.content;

		// if( this.eventTarget && o2.typeOf( this.eventTarget.addEvent ) === "function" ){
		// 	this.setEventTarget();
		// }

		this.fireAppEvent("postLoadWindow");
		this.fireAppEvent("queryLoadApplication");
		this.setContentEvent();

		//if (this.options.title) this.setTitle(this.options.title);
		if (this.stylePath){
			(this.window.node || this.content).loadCss(this.stylePath, function () {
				this.loadApplication(function(){
					this.fireAppEvent("postLoadApplication");
				}.bind(this));
				this.fireAppEvent("postLoad");
			}.bind(this));
		}else{
			this.loadApplication(function(){
				this.fireAppEvent("postLoadApplication");
			}.bind(this));
			this.fireAppEvent("postLoad");
		}
	},

	openInNewBrowser: function (noClose) {
		this.desktop.openBrowserApp = this.options.name;
		this.desktop.openBrowserStatus = (this.recordStatus) ? this.recordStatus() : null;
		var status = (this.desktop.openBrowserStatus) ? JSON.encode(this.desktop.openBrowserStatus) : "";

		var url = "../x_desktop/app.html?app=" + this.options.name + "&status=" + status;
		window.open(o2.filterUrl(url), "_blank");
		if (!this.inBrowser) if (!noClose) this.close();
	},
	openInNewWindow: function () {
		this.desktop.openBrowserApp = this.options.name;
		this.desktop.openBrowserStatus = (this.recordStatus) ? this.recordStatus() : null;
		window.open(o2.filterUrl("../x_desktop/app.html"), "_blank");
		if (!this.inBrowser) this.close();
	},
	setContentEvent: function () {
		//		this.content.addEvents({
		//			"resize": function(){
		//				if (this.onResize) this.onResize();
		//			}.bind(this)
		//		});
	},
	setCurrent: function () {
        if (this.desktop.currentApp == this) return true;
        if (this.desktop.currentApp) {
            this.desktop.currentApp.setUncurrent();
        }

        this.window.setCurrent();

        if (this.taskitem) this.taskitem.selected();
        this.desktop.currentApp = this;

        this.desktop.appCurrentList.erase(this);
        this.desktop.appCurrentList.push(this);

        if (this.window.isHide) {
            if (this.window.isMax) {
                this.window.maxSize(function () { this.fireAppEvent("current"); }.bind(this));
            } else {
                this.window.restore(function () { this.fireAppEvent("current"); }.bind(this));
            }
        } else {
            this.fireAppEvent("current");
        }
	},
	setUncurrent: function () {
		if (this.desktop.currentApp == this) {
			this.window.setUncurrent();
			if (this.taskitem) this.taskitem.unSelected();
			this.desktop.currentApp = null;
			this.fireAppEvent("uncurrent");
		}else{
			this.window.setUncurrent();
			if (this.taskitem) this.taskitem.unSelected();
		}
	},
	minSize: function () {
		this.fireAppEvent("queryMinSize");
		var p = this.taskitem.node.getPosition();
		this.setUncurrent();
		this.window.hide(p.x, p.y, function () {
			this.fireAppEvent("postMinSize");
		}.bind(this));
	},
	_minSize: function () {

		var p = this.taskitem.node.getPosition();
		this.setUncurrent();
		this.window.hide(p.x, p.y);
	},
	maxOrRestoreSize: function () {
		var max = true;
		if (this.window.isMax) max = false;
		this.fireAppEvent((max) ? "queryMaxSize" : "queryRestoreSize");

		this.window.maxOrRestoreSize(function () {
			this.fireAppEvent((max) ? "postMaxSize" : "postRestoreSize");
		}.bind(this));
	},
	maxSize: function (callback) {
		if (!this.window.isMax) {
			this.fireAppEvent("queryMaxSize");
			this.window.maxSize(function () {
				this.fireAppEvent("postMaxSize");
				if (callback) callback();
			}.bind(this));
		} else {
			if (callback) callback();
		}
	},
	_maxSize: function (callback) {
		this.window.maxSize();
	},
	restoreSize: function (callback) {
		this.fireAppEvent("queryRestoreSize");
		this.window.restoreSize(function () {
			this.fireAppEvent("postRestoreSize");
			if (callback) callback();
		}.bind(this));
	},
	_restoreSize: function (callback) {
		this.window.restoreSize();
	},
	refresh: function () {
		this.desktop.refreshApp(this);
	},
	close: function (hasTaskitem) {
		if (this.inBrowser) {
			window.open("", "_self").close();
			window.close();
		} else if( this.embeded ){

			this.window = null;
			this.fireAppEvent("queryClose");
			if (this.resizeFun && this.eventTarget) this.eventTarget.removeEvent("resize", this.resizeFun);
			this.fireAppEvent("postClose");
			o2.release(this);

		} else {
			this.fireAppEvent("queryClose");

			this.setUncurrent();
			this.window.close(function () {
				if (!hasTaskitem) this.taskitem.destroy();
				this.window = null;
				this.taskitem = null;
				if (this.resizeFun) layout.desktop.removeEvent("resize", this.resizeFun);
				this.desktop.closeApp(this, hasTaskitem);
				this.fireAppEvent("postClose");

				o2.release(this);
			}.bind(this));
		}
	},
	setTitle: function (str) {
		try {
			if (this.taskitem) {
				this.taskitem.textNode.set("text", str);
				this.taskitem.node.set("title", str + ((this.appId) ? "-" + this.appId : ""));
				this.taskitem.setTaskitemSize();
			}
			this.options.title = str;
			this.window.titleText.set("text", str);
		} catch (e) { }

	},
	loading: function(){
		// if (this.taskitem){
		// 	if (this.taskitem.refreshNode) this.taskitem.refreshNode.addClass("icon_taskLoading");
		// }
		// this.loadingNode = new Element("div", {
		// 	"styles": {
		// 		"height": "100%",
		// 		"width": "100%",
		// 		"overflow": "auto",
		// 		"position": "absolute",
		// 		"top": "0px",
		// 		"left": "0px",
		// 		"background-repeat": "no-repeat",
		// 		"background-position": "center"
		// 	}
		// }).inject(this.content);
		// this.loadingNode.addClass("icon_loading");
	},
	unLoading: function(){
		// if (this.taskitem){
		// 	if (this.taskitem.refreshNode) this.taskitem.refreshNode.removeClass("icon_taskLoading");
		// }
		// if (this.loadingNode) this.loadingNode.destroy();
	},


	//application事件
	onQueryLoad: function () { },
	onQueryLoadWindow: function () { },
	onLoadWindow: function () { },
	onPostLoadWindow: function () { },
	onQueryLoadApplication: function () { },
	onPostLoadApplication: function () { },
	onPostLoad: function () { },
	onResize: function () { },
	onQueryClose: function () { },
	onPostClose: function () { },
	onQueryMinSize: function () { },
	onPostMinSize: function () { },
	onQueryMaxSize: function () { },
	onPostMaxSize: function () { },
	onQueryRestoreSize: function () { },
	onPostRestoreSize: function () { },

	dialog: function (options) {
		MWF.require("MWF.xDesktop.Dialog", function () {
			options.markNode = this.content;
			var dlg = new MWF.xDesktop.Dialog(options);
			dlg.show();
		}.bind(this));
	},
	notice: function (content, type, target, where, offset) {
		if (window.mBox){
			if (!where) where = { "x": "right", "y": "top" };
			if (!target) target = this.content;
			if (!target) target = this.window.content;
			if (!type) type = "ok";
			var noticeTarget = target || layout.layout.contentNode;
			// 移动端如果向下滚动了就看不到了
			if (layout.mobile) {
				noticeTarget = $(document.body);
			}
			
			var off = offset;
			if (!off) {
				off = {
					x: 10,
					y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
				};
			}
			new mBox.Notice({
				type: type,
				position: where,
				move: false,
				target: noticeTarget,
				delayClose: (type == "error") ? 10000 : 5000,
				offset: off,
				content: content
			});
		}
	},
	confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
		MWF.require("MWF.xDesktop.Dialog", function () {
			var content = layout.mobile ? $(document.body) : this.content || $(document.body);
			var size = content.getSize();
			var x = 0;
			var y = 0;

			if (layout.mobile) {
				if (parseFloat(width) > size.x) {
					width = size.x - 40;
					x = 40;
				} else {
					x = (size.x - parseFloat(width)) / 2;
				}
				if (parseFloat(height) > size.y) {
					y = 0;
				} else {
					y = (size.y - parseFloat(height)) / 2;
				}
			} else {
				if (typeOf(e) == "element") {
					var position = e.getPosition(content);
					x = position.x;
					y = position.y;
				} else {
					if (Browser.name == "firefox") {
						x = parseFloat(e.event ? (e.event.clientX || e.event.x) : e.clientX);
						y = parseFloat(e.event ? (e.event.clientY || e.event.y) : e.clientY);
					} else {
						x = parseFloat(e.x || e.event.x);
						y = parseFloat(e.y || e.event.y);
					}

					if (e.target) {
						var position = e.target.getPosition(content);
						x = position.x;
						y = position.y;
					}
				}
				if (x + parseFloat(width) > size.x) {
					x = x - parseFloat(width);
				}
				if (x < 0) x = 0;
				if (y + parseFloat(height) > size.y) {
					y = y - parseFloat(height);
				}
				if (y < 0) y = 0;
				// 鼠标位置往左偏移
				x = x - 20;
			}


			var ctext = "";
			var chtml = "";
			if (typeOf(text).toLowerCase() == "object") {
				ctext = text.text;
				chtml = text.html;
			} else {
				ctext = text;
			}

			// var tmp = new Element("div", {"overflow": "hidden","padding": "10px", "padding-left": "60px", "width": ""+width+"px"}).inject(document.body);
			// if (chtml) tmp.set("html", chtml);
			// if (ctext) tmp.set("text", ctext);
			// height = tmp.getSize().y;
			// tmp.destroy();

			var dlg = new MWF.xDesktop.Dialog({
				"title": title,
				"style": style || "o2",
				"top": y,
				"left": x,
				"fromTop": y,
				"fromLeft": x,
				"width": width,
				"height": height,
				"text": ctext,
				"html": chtml,
				"container": content,
				"mark": (mask) ? true : false,
				"maskNode": mask || content,
				"buttonList": [
					{
						"type": "ok",
						"text": MWF.LP.process.button.ok,
						"action": ok
					},
					{
						"type": "cancel",
						"text": MWF.LP.process.button.cancel,
						"action": cancel
					}
				]
			});

			switch (type.toLowerCase()) {
				case "success":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "error":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "info":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "warn":
					dlg.content.setStyle("background-image", "url()");
					break;
				default:
				//dlg.content.setStyle("background-image", "");
			}
			dlg.show();
			if (callback) callback(dlg);
		}.bind(this));
	},
	dlg: function (type, e, title, text, width, height, actions, mask, style) {
		MWF.require("MWF.xDesktop.Dialog", function () {
			var size = this.content.getSize();
			var p = (e) ? MWF.getEPointer(e) : MWF.getCenter({ "x": width, "y": height }, this.content, this.content);
			var x = p.x || 0;
			var y = p.y || 0;

			if (x + parseFloat(width) > size.x) {
				x = x - parseFloat(width);
			}
			if (x < 0) x = 0;
			if (y + parseFloat(height) > size.y) {
				y = y - parseFloat(height);
			}
			if (y < 0) y = 0;

			var ctext = "";
			var chtml = "";
			if (typeOf(text).toLowerCase() === "object") {
				ctext = text.text;
				chtml = text.html;
			} else {
				ctext = text;
			}

			var dlg = new MWF.xDesktop.Dialog({
				"title": title,
				"style": style || "o2",
				"top": y,
				"left": x - 20,
				"fromTop": y,
				"fromLeft": x - 20,
				"width": width,
				"height": height,
				"text": ctext,
				"html": chtml,
				"container": this.content,
				"mark": (mask) ? true : false,
				"maskNode": mask || this.content,
				"buttonList": actions
			});

			switch (type.toLowerCase()) {
				case "success":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "error":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "info":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "warn":
					dlg.content.setStyle("background-image", "url()");
					break;
				default:
			}
			dlg.show();
		}.bind(this));
	},
	alert: function (type, e, title, text, width, height, callback) {
		MWF.require("MWF.widget.Dialog", function () {
			var size = $(document.body).getSize();
			var x = 0, y = 0;
			if (e === "center") {
				if( layout.mobile ){
					x = (size.x - parseFloat(width)) / 2;
					y = (size.y - parseFloat(height)) / 2;
				}else{
                    var p = o2.getCenterPosition(this.content, width, height);
                    x = p.x;
                    y = p.y;
				}
			} else {
				x = parseFloat(e.event.x);
				y = parseFloat(e.event.y);
				if (Browser.name == "firefox") {
					x = parseFloat(e.event.clientX);
					y = parseFloat(e.event.clientY);
				}
				x = x - parseFloat(width) / 2;
				y = y - parseFloat(height) / 2;
			}

			if (x + parseFloat(width) > size.x) {
				x = x - parseFloat(width);
			}
			if (x < 0) x = 0;

			if (y + parseFloat(height) > size.y) {
				y = y - parseFloat(height);
			}
			if (y < 0) y = 0;


			var ctext = "";
			var chtml = "";
			if (typeOf(text).toLowerCase() == "object") {
				ctext = text.text;
				chtml = text.html;
			} else {
				ctext = text;
			}

			var dlg = new MWF.DL({
				"title": title,
				"style": "o2",
				"top": y,
				"left": x,
				"fromTop": y,
				"fromLeft": x,
				"width": width,
				"height": height,
				"text": ctext,
				"html": chtml,
				"maskNode": layout.mobile ? $(document.body) : this.content,
				"container": layout.mobile ? $(document.body) : this.content,
				"buttonList": [
					{
						"text": MWF.LP.process.button.ok,
						"action": function () {
							if( typeOf(callback) === "function" )callback();
							this.close();
						}
					}
				]
			});

			switch (type.toLowerCase()) {
				case "success":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "error":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "info":
					dlg.content.setStyle("background-image", "url()");
					break;
				case "warn":
					dlg.content.setStyle("background-image", "url()");
					break;
				default:
			}
			dlg.content.setStyle("overflow","auto");
			dlg.show();
		}.bind(this));
	}
});
